
*** Figure C1
use "data\out\estsample.dta", clear 

rename maalepktnr Målepunktnr 
fmerge m:1 Målepunktnr using "data\in\kunder_koordinater_grunnkretser_adresser.dta", keep(match) keepusing(grunnkretsnummer) nogenerate
rename Målepunktnr maalepktnr  

g byte PeakxEvent = Peak*EventDay
g byte ShoulderxEvent = shoulder*EventDay

* per grunnkrets 
glevelsof grunnkretsnummer, clean local(grunnkretsliste)
foreach i in `grunnkretsliste' {
di `i'
ivreghdfe lnforbruk c.temp##c.temp##c.temp temp_* Peak PeakxEvent ShoulderxEvent Peakelcar shoulder shoulderelcar ///
  (Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Effektprisshoulder Effektprisshoulderelcar =  TPE TNPE TPnextdays TNPnextdays TPEelcar TNPEelcar TPnextdayselcar TNPnextdayselcar TsE TsEelcar) if `i' == grunnkretsnummer, a(maalepktnr dato) cluster(maalepktnr)
est store g`i'  
estadd ysumm  
}

foreach i in 6120301 6120302 6120303 6120304 6120305 6120306 {
di `i'
ivreghdfe lnforbruk c.temp##c.temp##c.temp temp_* Peak PeakxEvent ShoulderxEvent Peakelcar shoulder shoulderelcar ///
  (Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Effektprisshoulder Effektprisshoulderelcar =  TPE TNPE TPnextdays TNPnextdays TPEelcar TNPEelcar TPnextdayselcar TNPnextdayselcar TsE TsEelcar) if `i' == grunnkretsnummer, a(maalepktnr dato) cluster(maalepktnr)
est store g`i'  
estadd ysumm  
}


estout g* using "output\results_pergrunnkrets.txt", replace type ///
  keep(E* Peak* shoulder*) ///
  cells(b( fmt(3)) se(fmt(3)) p(fmt(3))) indicate(temp) collabels(none) legend ///
  varlabels(TPE TP TNPE TNP) ///
  stats(ymean r2 N N_clust, fmt(3 3 0 0)) style(tab)

// Coefficients were plotted using QGIS 3.22.5 and the admnistrative grunnkrets and population density layers from https://www.kartverket.no/


*** Figure C2
use "data\in\customer_payments_extrainfoSept23.dta", clear
keep if Treat==1
drop if noncomplier==1
replace pdiff=pdiff/9.5377  // convert the bill difference into USD using Nov 1, 2020 rate
gen pdiffm=pdiff/(3+11/31)  // convert from the (3 months + 11 days) of the experiment into a monthly bill difference
sum pdiffm, d

histogram pdiffm, bin(50) xline(0, lpattern(solid)) xline(-2.2, lpattern(shortdash)) xline(-34.0, lpattern(shortdash_dot)) xline(12.2, lpattern(shortdash_dot)) color(blue%40) xscale(range(-70 30))  xtitle("Monthly bill difference (USD)") graphregion(color(white)) bgcolor(white)
graph export output\welfare.png, replace




*** Figure C3
import excel using "data\in\elbiltyper_batteri.xlsx", first sheet(Sheet1) clear
label variable Battery "Battery capacity (kWh)"
graph box Battery [fweight=Antall]
graph export output\elbil_whiskers_all.png, replace
